ostree-prepare-root as init: exec init from deployment if run as PID1
authorWilliam Manley <will@williammanley.net>
Mon, 18 Jul 2016 16:03:11 +0000 (17:03 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 2 Aug 2016 19:07:25 +0000 (19:07 +0000)
This supports running ostree on embedded platforms without an initrd.
Specificially I'm trying to do bringup on an NVidia Tegra based Jetson TK1
dev board.

Closes: #403
Approved by: cgwalters

src/switchroot/ostree-prepare-root.c

index df3e32198fc260c0b98bdfdc6db4ab8bc65775fc..a233007ef6e894a826427451d2ba299c3c10175b 100644 (file)
@@ -156,12 +156,10 @@ main(int argc, char *argv[])
   int orig_cwd_dfd;
 
   if (argc < 2)
-    {
-      fprintf (stderr, "usage: ostree-prepare-root SYSROOT\n");
-      exit (EXIT_FAILURE);
-    }
+    root_mountpoint = "/";
+  else
+    root_mountpoint = argv[1];
 
-  root_mountpoint = argv[1];
   deploy_path = resolve_deploy_path (root_mountpoint);
 
   /* Create a temporary target for our mounts in the initramfs; this will
@@ -303,6 +301,15 @@ main(int argc, char *argv[])
       perrorv ("failed to MS_MOVE %s to %s", deploy_path, root_mountpoint);
       exit (EXIT_FAILURE);
     }
-  
-  exit (EXIT_SUCCESS);
+
+  if (getpid() == 1)
+    {
+      execl ("/sbin/init", "/sbin/init", NULL);
+      perrorv ("failed to exec init inside ostree");
+      exit (EXIT_FAILURE);
+    }
+  else
+    {
+      exit (EXIT_SUCCESS);
+    }
 }